home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 46
/
Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso
/
-in_the_mag-
/
reader_requests
/
pdflib
/
p_hyper.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-09-16
|
2KB
|
93 lines
/* p_hyper.c
* Copyright (C) 1997-98 Thomas Merz. All rights reserved.
*
* PDFlib routines for hypertext stuff, e.g. bookmarks
*/
/*
* Restrictions: bookmarks cannot be nested
*/
#include "p_intern.h"
static void
pdf_write_outline_dict(PDF *p, pdf_outline *out)
{
pdf_begin_obj(p, out->self);
pdf_begin_dict(p);
(void) fprintf(p->fp, "/Parent %ld 0 R\n", out->parent);
/* outline destination */
(void) fprintf(p->fp, "/Dest [%ld 0 R /XYZ 0 0 0]\n", out->page);
(void) fputs("/Title ", p->fp); /* outline text */
pdf_quote_string(p, out->text);
(void) fputs("\n", p->fp);
if (out->prev)
(void) fprintf(p->fp, "/Prev %ld 0 R\n", out->prev);
if (out->next)
(void) fprintf(p->fp, "/Next %ld 0 R\n", out->next);
#ifdef NOTYET
if (out->first) {
(void) fprintf(p->fp, "/First %ld 0 R\n", out->first);
(void) fprintf(p->fp, "/Last %ld 0 R\n", out->last);
(void) fprintf(p->fp, "/Count %d\n", out->count);
}
#endif
pdf_end_dict(p);
pdf_end_obj(p);
}
void
pdf_write_outlines(PDF *p)
{
int i;
if (p->outlines_id == 0) /* no outlines, return */
return;
pdf_begin_obj(p, p->outlines_id);
pdf_begin_dict(p);
if (p->outline_count > 0) {
(void) fprintf(p->fp, "/Count %d\n", p->open_outlines);
(void) fprintf(p->fp, "/First %ld 0 R /Last %ld 0 R\n",
p->outlines[0].self, p->outlines[p->outline_count-1].self);
/*p->outlines[0].first.id, p->outlines[0].last.id);*/
}
pdf_end_dict(p);
pdf_end_obj(p);
for (i = 0; i < p->outline_count; i++)
pdf_write_outline_dict(p, &p->outlines[i]);
}
/* add bookmark text with current page as destination */
void
PDF_add_outline(PDF *p, char *text)
{
if (p->outline_count == 0)
p->outlines_id = pdf_alloc_id(p);
p->open_outlines++;
p->outlines[p->outline_count].text = text;
p->outlines[p->outline_count].page = p->pages[p->current_page];
p->outlines[p->outline_count].self = pdf_alloc_id(p);
p->outlines[p->outline_count].parent= p->outlines_id; /* HACK */
if (p->outline_count > 0) {
p->outlines[p->outline_count].prev =
p->outlines[p->outline_count - 1].self;
p->outlines[p->outline_count - 1].next =
p->outlines[p->outline_count].self;
}
p->outline_count++;
}